import {api} from "./api";

class Commit {
    async do() {

        // 获取授权小程序
        const apps = await api.getMiniAppList();
        console.log("获取到授权小程序", apps);

        // 获取草稿箱
        const draft = await api.getDraftList();
        console.log("获取最近草稿箱:", draft);

        // 将草稿箱内容添加到模板
        console.log("将草稿箱内容添加到模板", draft.draft_id);
        await api.addToTemplate(draft.draft_id);

        // 将草稿箱提交模版
        const tmpl = await api.getTemplateList();
        console.log("获取到最新模版", tmpl);

        // 将代码提交到体验版
        for (const app of apps) {
            console.log("提交到体验版", app.app_name, app.appid, tmpl.template_id, tmpl.user_version, tmpl.user_desc);
            await api.commitTemplate(app.appid, tmpl.template_id, tmpl.user_version, tmpl.user_desc);
            console.log("体验版二维码地址：", app.app_name, await api.getQrCode(app.appid))
        }
    }
}

(async () => {
    try {
        await (new Commit()).do()
    } catch (e) {
        console.log(e.message)
    }
})();
